package com.tt.dao;

import java.util.List;
import java.util.Set;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.hibernate.query.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.tt.entity.Hotel;
import com.tt.entity.Question;
import com.tt.entity.Reply;
import com.tt.entity.User;

@Repository
@Transactional
public class CommunityDaoImpl {
	@Resource
	private SessionFactory sessionFactory;
	//发布问题
	public int  addQuestion(Question question,int uid){
		User user = this.sessionFactory.getCurrentSession().load(User.class, uid);
		question.setUser(user);
		int addQuestion=(int) this.sessionFactory.getCurrentSession().save(question);
		return addQuestion;
	}
	public List<Question> findAllQuestion(){
		Query query = this.sessionFactory.getCurrentSession().createQuery("from Question");
		List<Question> list = query.list();
		return list;
	}
	public boolean addReply(int id,Reply reply,int uid){
		Question question = this.sessionFactory.getCurrentSession().load(Question.class, id);
		User user = this.sessionFactory.getCurrentSession().load(User.class, uid);
		reply.setQuestion(question);
		reply.setUser(user);
		this.sessionFactory.getCurrentSession().save(reply);
		return true;
	}
	
}
